<template lang="pug">
  van-datetime-picker(ref="pick" :value="value" type="datetime" @confirm="confim" @cancel="cancel" :formatter="formatter")
</template>
<script>
// import { addZero } from '../../../../../../../../common/utils/validate'
import _ from 'lodash'

export default {
  name: 'dateRender',
  components: {},
  props: ['config', 'editor', 'value', 'readonly'],
  methods: {
    confim() {
      let dateTime = this.$refs.pick.$children[0].getValues()
      let date = _.chunk(dateTime, 3)[0] // 年月日
      _.forEach(date, (one, index) => {
        date[index] = one.slice(0, -1)
      })
      let time = _.chunk(dateTime, 3)[1] // 时分
      let dateValue = date.join('-') + ' ' + time.join(':') + ':00'
      this.$emit('input', dateValue)
      this.$emit('popupClose', dateValue)
    },
    cancel() {
      this.$emit('popupClose')
    },
    formatter(type, value) {
      if (type === 'year') {
        return `${value}年`
      } else if (type === 'month') {
        return `${value}月`
      } else if (type === 'day') {
        return `${value}日`
      }
      return value
    }
  }
}
</script>
<style lang="scss">

</style>
